<!-- $Id: goods_export.htm 17107 2010-04-15 03:29:13Z liuhui $ -->
<?php echo $this->fetch('pageheader.htm'); ?>
<script type="text/javascript" src="../plugins/WdatePicker/js/lang/zh-cn.js"></script>
<link rel="stylesheet" type="text/css" href="../plugins/WdatePicker/js/skin/WdatePicker.css" />
<script type="text/javascript" src="../plugins/WdatePicker/js/WdatePicker.js"></script>
<link rel="stylesheet" type="text/css" href="../plugins/autocomplete/jquery.autocomplete.css">		
<script type="text/javascript" src="../plugins/autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript">	
	//自动下拉菜单 for category
	var cat_count = 0;
	function auto_cat(obj,returnobj){		
		jQuery(obj).autocomplete({		
			url: '../plugins/autocomplete/search.php?type=cat',
			autoFill:true,	
			minChars:2,		
			selectFirst:true,			
			sortFunction: function(a, b, filter) {			
				var f = filter.toLowerCase();
				var fl = f.length;
				var a1 = a.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
				var a1 = a1 + String(a.data[0]).toLowerCase();
				var b1 = b.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
				var b1 = b1 + String(b.data[0]).toLowerCase();
				if (a1 > b1) {
					return 1;
				}
				if (a1 < b1) {
					return -1;
				}
				return 0;
			},
			showResult: function(value, data) {
				return '<span style="color:red">' + value + '</span>';
			},
			onItemSelect: function(item) {						
				jQuery(returnobj).val(item.data).trigger("change");				
			},
			onNoMatch:function(){
				jQuery(returnobj).val('').trigger("change");
			},
			maxItemsToShow: 50
		});
	}


	jQuery(function() {	
		//分类
		auto_cat('#cat_name','#cat_id');	
		//商家
		jQuery("#suppliers_name").autocomplete({		
			url: '../plugins/autocomplete/search.php?type=suppliers',
			autoFill:true,	
			minChars:2,
			selectFirst:true,				
			sortFunction: function(a, b, filter) {			
				var f = filter.toLowerCase();
				var fl = f.length;
				var a1 = a.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
				var a1 = a1 + String(a.data[0]).toLowerCase();
				var b1 = b.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
				var b1 = b1 + String(b.data[0]).toLowerCase();
				if (a1 > b1) {
					return 1;
				}
				if (a1 < b1) {
					return -1;
				}
				return 0;
			},
			showResult: function(value, data) {
				return '<span style="color:red">' + value + '</span>';
			},
			onItemSelect: function(item) {						
				jQuery("#suppliers_id").val(item.data);				
			},
			
			onNoMatch:function(){
				jQuery("#suppliers_id").val('');		
			},
			maxItemsToShow: 50
		});
	
	
	});

</script>
<strong></strong>
<table width="100%">
<tr>
  <td>
  <div class="main-div" style="background-color: white;">
   <h3><center><?php echo $this->_var['lang']['export_condition']; ?></center></h3>
  <div>
    <form action="purchase_export.php" method="post" name="searchForm" onsubmit="return queryGoods(this)">
      <strong><?php echo $this->_var['lang']['custom_goods_search']; ?></strong>
      <!-- 分类 -->
	  <?php echo $this->_var['lang']['custom_goods_cat']; ?>
	  <input name="cat_name" id="cat_name"  value="<?php echo $this->_var['goods']['cat_name']; ?>">
            <input id="cat_id" value="<?php echo $this->_var['goods']['cat_id']; ?>" name="cat_id" type="hidden"  onchange="hideCatDiv()" >
      <!-- 品牌 -->
      <select name="brand_id"><option value="0"><?php echo $this->_var['lang']['custom_goods_brand']; ?></option><?php echo $this->html_options(array('options'=>$this->_var['brand_list'])); ?></select>
	  <!-- 供货商 -->
	 <?php echo $this->_var['lang']['custom_suppliers_name']; ?> 
	  <input name="suppliers_name" id="suppliers_name" value="<?php echo $this->_var['goods']['suppliers_name']; ?>" style="width:250px!important;">
	 <input name="suppliers_id" id="suppliers_id" value="<?php echo $this->_var['goods']['suppliers_id']; ?>" type="hidden">
      <!-- 关键字 -->
      <?php echo $this->_var['lang']['custom_keyword']; ?><input name="keyword" type="text" size="10"/>
      <!-- 搜索 -->
      <input type="submit" name="search_submit" id="search_submit" value="<?php echo $this->_var['lang']['export_condition_search']; ?>" class="button"  />
    </form>
  </div>
  <table>
  <tr>
    <td width="46%"><select name="src_goods_lists" id="src_goods_lists" size="14" style="width:100%" multiple="true">
              </select></td>
    <td rowspan="2" width="8%" style="text-align:center;">
      <p><input type="button" value=">>" id="addAllGoods" class="button" /></p>
      <p><input type="button" value=">" id="addGoods" class="button" /></p>
      <p><input type="button" value="<" id="delGoods" class="button" /></p>
      <p><input type="button" value="<<" id="delAllGoods" class="button" /></p>
    </td>
    <td width="46%"><select name="dst_goods_lists" id="dst_goods_lists" size="14" style="width:100%" multiple="true">
              </select></td>
  </tr>
  </table>
  <div style="display:none"><strong>开始日期</strong> <input id="start_date" type="Text" name="planStartTime" class="Wdate"  size="12" id="planStartTime"
					onFocus="WdatePicker({skin:'default',startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})"
					style="cursor: hand;" value="<?php echo $this->_var['start_date']; ?>"></div>
  <div>
     <!-- 导出的数据格式 -->
      <select name="data_format" id="data_format"  style="display:none"><?php echo $this->html_options(array('options'=>$this->_var['data_format'],'selected'=>'magento')); ?></select>
      <div id="export_format">
      </div>
  </div>
  </div>
  </td>
</tr>
</table>
<div id="ecshop_form" style="display:none">
    <form action="purchase_export.php" method="post" name="theForm" onsubmit="return formValidate0()">
    <table width="100%" >
      <tr>
        <td class="label"><?php echo $this->_var['lang']['select_charset']; ?></td>
        <td>
            <select name="charset" >
              <option value="UTF8">UTF8</option>
              <option value="GB2312" selected="selected">GB2312</option>
              <option value="GBK">GBK</option>
            </select>
        </td>
      </tr>
      <tr>
        <td>
            <input name="cat_id" type="hidden" value="" />
            <input name="brand_id" type="hidden" value="" />
            <input name="keyword" type="hidden" value="" />
            <input name="goods_ids" type="hidden" value="" />
            <input type="hidden" name="act" value="act_export_ecshop">
        </td>
        <td>
        <input name="submit" type="submit" id="submit" value="<?php echo $this->_var['lang']['button_submit']; ?>" class="button"  />
        </td>
      </tr>
    </table>
    </form>
</div>

<div id="magento_form" style="display:none">
    <form action="purchase_export.php" method="post" name="theForm_magento" onsubmit="return formValidate_magento()">
    <table width="100%" >
      <tr>
        <td class="label"><?php echo $this->_var['lang']['select_charset']; ?></td>
        <td>
            <select name="charset" >
              <option value="UTF8">UTF8</option>
              <option value="GB2312" selected="selected">GB2312</option>
              <option value="GBK">GBK</option>
            </select>
        </td>
      </tr>
      <tr>
        <td>
            <input name="cat_id" type="hidden" value="" />
            <input name="brand_id" type="hidden" value="" />
            <input name="keyword" type="hidden" value="" />
            <input name="goods_ids" type="hidden" value="" />
            <input type="hidden" name="act" value="act_export_magento">
        </td>
        <td>
		
		
        <input name="submit" type="submit" id="submit" value="<?php echo $this->_var['lang']['button_submit']; ?>" class="button" />
        </td>
      </tr>
    </table>
    </form>
</div>


<?php echo $this->smarty_insert_scripts(array('files'=>'../js/utils.js,validator.js')); ?>
<script language="JavaScript">
var post_express_not_null = "<?php echo $this->_var['lang']['post_express_not_null']; ?>";
var express_not_null = "<?php echo $this->_var['lang']['express_not_null']; ?>";
var ems_not_null = "<?php echo $this->_var['lang']['ems_not_null']; ?>";
var custom_goods_field_not_null = "<?php echo $this->_var['lang']['custom_goods_field_not_null']; ?>";



    var elements;
    onload = function()
    {
        // 开始检查订单
        startCheckOrder();
    }

    function formValidate0()
    {
	
        var src_obj = document.forms['searchForm'];
        var dst_obj = document.forms['theForm'];
        copy_search_result(src_obj, dst_obj);
        return true;
    }
	
	  function formValidate_magento()
    {
	
        var src_obj = document.forms['searchForm'];
        var dst_obj = document.forms['theForm_magento'];
        copy_search_result(src_obj, dst_obj);
        return true;
    }
	
	
    /**
     * 检查输入是否完整
     */
    function formValidate2()
    {
        var elements = document.forms['theForm2'].elements;
        var msg = '';

        if (parseFloat(elements['post_express'].value) <= 0)
        {
            msg += post_express_not_null + '\n';
        }
        if (parseFloat(elements['express'].value) <= 0)
        {
            msg += express_not_null + '\n';
        }
        if (msg.length > 0)
        {
            alert(msg);
            return false;
        }
        else
        {
            var src_obj = document.forms['searchForm'];
            var dst_obj = document.forms['theForm2'];
            copy_search_result(src_obj, dst_obj);
            return true;
        }
    }

    /**
     * 检查输入是否完整
     */
    function formValidate1()
    {
        var elements = document.forms['theForm1'].elements;
        var msg = '';

        if (parseFloat(elements['post_express'].value) <= 0)
        {
            msg += post_express_not_null + '\n';
        }
        if (parseFloat(elements['express'].value) <= 0)
        {
            msg += express_not_null + '\n';
        }
        if (parseFloat(elements['ems'].value) <= 0)
        {
            msg += ems_not_null + '\n';
        }
        if (msg.length > 0)
        {
            alert(msg);
            return false;
        }
        else
        {
            var src_obj = document.forms['searchForm'];
            var dst_obj = document.forms['theForm1'];
            copy_search_result(src_obj, dst_obj);
            return true;

        }
    }

    /* 检查输入是否完整 */
    function formValidate4 ()
    {
        var elements = document.forms['theForm4'].elements;
        var msg = '';
        if (elements['dst_goods_fields'].options.length <= 0)
        {
            msg += custom_goods_field_not_null + '\n';
        }
        if (msg.length > 0)
        {
            alert(msg);
            return false;
        }
        else
        {
            elements['custom_goods_export'].value = '';
            for (var i=0,l=elements['dst_goods_fields'].options.length; i<l; i++)
            {
                var separator = (i==0)?'':',';
                elements['custom_goods_export'].value += separator + elements['dst_goods_fields'].options[i].value;
            }
            var src_obj = document.forms['searchForm'];
            var dst_obj = document.forms['theForm4'];
            copy_search_result(src_obj, dst_obj);
            return true;
        }
    }

    /**
     * 检查输入是否完整
     */
    function formValidate5()
    {
        var elements = document.forms['theForm5'].elements;
        var msg = '';

        if (parseFloat(elements['post_express'].value) <= 0)
        {
            msg += post_express_not_null + '\n';
        }
        if (parseFloat(elements['express'].value) <= 0)
        {
            msg += express_not_null + '\n';
        }
        if (msg.length > 0)
        {
            alert(msg);
            return false;
        }
        else
        {
            var src_obj = document.forms['searchForm'];
            var dst_obj = document.forms['theForm5'];
            copy_search_result(src_obj, dst_obj);
            return true;
        }
    }

    function copy_search_result(src_obj, dst_obj)
    {
        dst_obj.cat_id.value = src_obj.cat_id.value;
        dst_obj.brand_id.value = src_obj.brand_id.value;
        dst_obj.keyword.value = src_obj.keyword.value;
        var goods_lists = Utils.$('dst_goods_lists');
        for (var i=0,l=goods_lists.options.length; i<l; i++)
        {
            var separator = (i==0)?'':',';
            dst_obj.goods_ids.value += separator + goods_lists.options[i].value;
        }
    }

    /**
     * 绑定商品类型控件事件
     */
    if(Utils.$('goods_type'))
    {
        Utils.$('goods_type').onchange = function ()
        {
            Ajax.call('purchase_export.php?is_ajax=1&act=get_goods_fields&cat_id='+this.value, '' , goodsFieldsResponse , 'POST', 'JSON');
        }
    }

    function goodsFieldsResponse (result)
    {
        if (result.error > 0)
        {
            alert(result.message);
            return;
        }
        Utils.$('src_goods_fields').innerHTML = '';
        for (var key in result.content)
        {
            if (typeof (result.content[key]) == 'string')
            {
                var new_opt = document.createElement('OPTION');
                new_opt.value = key;
                new_opt.innerHTML = result.content[key];
                Utils.$('src_goods_fields').appendChild(new_opt);
            }
        }
    }
    /* 搜索商品列表 */
    function queryGoods(obj)
    {
        var filters = new Object;
        filters.cat_id = obj.cat_id.value;
        filters.brand_id = obj.brand_id.value;
        filters.keyword = obj.keyword.value;
		filters.suppliers_id = obj.suppliers_id.value;
        Ajax.call('purchase_export.php?is_ajax=1&act=get_goods_list', filters, queryGoodsResponse , 'POST', 'JSON');
        return false;
    }

    function queryGoodsResponse (result)
    {
        if (result.error > 0)
        {
            alert(result.message);
            return;
        }
        Utils.$('src_goods_lists').innerHTML = '';
        for (var i=0,l=result.content.length;i<l;++i)
        {
            var new_opt = document.createElement('OPTION');
            new_opt.value = result.content[i].goods_id;
            new_opt.innerHTML = result.content[i].goods_name;
            Utils.$('src_goods_lists').appendChild(new_opt);
        }
    }


    /* 操作自定义导出商品的Select Box */
    var MySelectBox;
    var MySelectBox2;
    if (!MySelectBox)
    {
        var global = $import("../js/global.js","js");
        global.onload = global.onreadystatechange= function()
        {
            if(this.readyState && this.readyState=="loading")return;
            var selectbox = $import("js/selectbox.js","js");
            selectbox.onload = selectbox.onreadystatechange = function()
            {
                if(this.readyState && this.readyState=="loading")return;
                MySelectBox = new SelectBox('src_goods_fields', 'dst_goods_fields');
                MySelectBox2 = new SelectBox('src_goods_lists', 'dst_goods_lists', true);
            }
        }
    }
    if (Utils.$('addItem'))
    {
        Utils.$('addItem').onclick = function ()
        {
            MySelectBox.addItem();
        }
    }
    if (Utils.$('delItem'))
    {
        Utils.$('delItem').onclick = function ()
        {
            MySelectBox.delItem();
        }
    }
    if (Utils.$('addAllItem'))
    {
        Utils.$('addAllItem').onclick = function ()
        {
            MySelectBox.addItem(true);
        }
    }
    if (Utils.$('delAllItem'))
    {
        Utils.$('delAllItem').onclick = function ()
        {
            MySelectBox.delItem(true);
        }
    }
    if (Utils.$('src_goods_fields'))
    {
        Utils.$('src_goods_fields').ondblclick = function ()
        {
            MySelectBox.addItem();
        }
    }
    if (Utils.$('dst_goods_fields'))
    {
        Utils.$('dst_goods_fields').ondblclick = function ()
        {
            MySelectBox.delItem();
        }
    }
    if (Utils.$('mvUp'))
    {
        Utils.$('mvUp').onclick = function ()
        {
            MySelectBox.moveItem('up');
        }
    }
    if (Utils.$('mvDown'))
    {
        Utils.$('mvDown').onclick = function ()
        {
            MySelectBox.moveItem('down');
        }
    }

    if (Utils.$('addGoods'))
    {
        Utils.$('addGoods').onclick = function ()
        {
            MySelectBox2.addItem();
        }
    }
    if (Utils.$('delGoods'))
    {
        Utils.$('delGoods').onclick = function ()
        {
            MySelectBox2.delItem();
        }
    }
    if (Utils.$('addAllGoods'))
    {
        Utils.$('addAllGoods').onclick = function ()
        {
            MySelectBox2.addItem(true);
        }
    }
    if (Utils.$('delAllGoods'))
    {
        Utils.$('delAllGoods').onclick = function ()
        {
            MySelectBox2.delItem(true);
        }
    }
    if (Utils.$('src_goods_lists'))
    {
        Utils.$('src_goods_lists').ondblclick = function ()
        {
            MySelectBox2.addItem();
        }
    }
    if (Utils.$('dst_goods_lists'))
    {
        Utils.$('dst_goods_lists').ondblclick = function ()
        {
            MySelectBox2.delItem();
        }
    }

    /**
     * 上一次操作的对象
     */
    window.last_form = new Object;
    /**
     * 初始化导出格式
     */
    function init_data_format ()
    {
        var _format = Utils.$('data_format');
        show_data_format(_format.value);
        _format.onchange = function ()
        {
            show_data_format(this.value);
        }
    }

    /**
     * 显示要导出的格式页面
     *
     * @param page string 页面
     *
     * @return void
     */
    function show_data_format (page)
    {
        try
        {
            window.last_form.style.display = 'none';
        }
        catch (e)
        {
        }
        var _page = Utils.$(page+'_form');
        _page.style.display = '';
        Utils.$('export_format').appendChild(_page);
        window.last_form = _page;
    }

    if (Browser.isIE)
    {
        window.attachEvent("onload", init_data_format);
    }
    else
    {
        window.addEventListener("load", init_data_format, false);
    }
	
	
</script>

<?php echo $this->fetch('pagefooter.htm'); ?>
